This page last changed on Jul 20, 2009 by aunger.

Example folders:

  • Application Data
  • Application Support

Location

SYSTEM:

  • Windows: /Documents and Settings/All Users/Application Data/<vendor>/<application name>
  • Windows Vista: /ProgramData/<vendor>/<application name>
  • OS X: /Library/Application Support/<application name>
  • Linux: /usr/lib/<application name>

USER:

  • Windows: ~/Application Data/<vendor>/<application name>
  • Windows Vista: ~/AppData/Roaming/<vendor>/<application name>
  • OS X: ~/Library/Application Support/<application name>
  • Linux: ~/.<application name>

Possible Solutions

  • on windows jna can probably be used to get the current shell, and call the SHGetFolderPath function.
  • on osx the following class is availble:
    • com.apple.eio.FileManager which has a findFolder method. It isn't clear yet where to find the available folder types.

Windows Docs:

Pre Vista Info: http://msdn.microsoft.com/en-us/library/bb762494%28VS.85%29.aspx
Vista Info: http://msdn.microsoft.com/en-us/library/bb762584%28VS.85%29.aspx

Code examples

(Some language syntax (e.g. class definition) ignored for brevity)

Useful example code:
http://mail.python.org/pipermail/python-list/2005-September/341702.html

On Mac (Application Support folder):

import com.apple.eio.FileManager;
  
String folder;         

// System folder      
folder = FileManager.findFolder(FileManager.kLocalDomain, FileManager.OSTypeToInt("asup"));        

// User folder  
folder = FileManager.findFolder(FileManager.kUserDomain, FileManager.OSTypeToInt("asup"));

On Windows XP (Application Data folder):

import com.sun.jna.Library;  
import com.sun.jna.Native;  
import com.sun.jna.PointerType;  
import com.sun.jna.win32.W32APITypeMapper;  
import com.sun.jna.win32.W32APIFunctionMapper; 
   
class HANDLE extends PointerType {}  
class HWND extends PointerType {}    

int CSIDL_COMMON_APPDATA = 35; //system folder  
int CSIDL_APPDATA = 26;        //user folder
     
int SHGFP_TYPE_CURRENT = 0;  
int SHGFP_TYPE_DEFAULT = 1;    

int MAX_PATH = 255;    

Map<String, Object> unicodeOptions = new HashMap<String, Object>(); 
unicodeOptions.put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); 
unicodeOptions.put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);        

interface Sh32Library extends Library   
{          
    Sh32Library INSTANCE = (Sh32Library)                  
        Native.loadLibrary("shell32", Sh32Library.class, unicodeOptions); //shell32.dll
     
    int SHGetFolderPath(HWND hwndOwner, int nFolder, HANDLE hToken, int dwFlags, char[] pszPath);  
}        

char[] chPath = new char[MAX_PATH+1];
int rcode = Sh32Library.INSTANCE.SHGetFolderPath(null, 
                                                 CSIDL_COMMON_APP_DATA,                                            
                                                 null,
                                                 SHGFP_TYPE_CURRENT,
                                                 chPath);  // rcode == 0: success
String path = new String(chPath);    
path = path.substring(0, path.indexOf(0)); //trim C string at null char 
File userFolder = new File(path);
Document generated by Confluence on Jan 27, 2014 16:56